package servlet;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Student;
import util.DBHelper;

public class BaseServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		try {
			String m = req.getParameter("m");
			
//			System.out.println(m);
//			System.out.println(1);

			Method method = this.getClass().getDeclaredMethod(m, HttpServletRequest.class,HttpServletResponse.class);
//			System.out.println(2);

			method.invoke(this, req,res);
//			System.out.println(3);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		doGet(req, res);
	}

	@Override
	public void destroy() {
		DBHelper.close();
	}

	@Override
	public void init() throws ServletException {
		DBHelper.conn();
	}
	
}
